﻿@{
    ViewBag.Title = "Schedule";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<link href="~/Content/css/fullcalendar-3.8.2/fullcalendar.min.css" rel="stylesheet" />
    @*<script src="~/Content/js/fullcalendar-3.8.2/jquery.min.js"></script>*@
        <script src="~/Content/js/fullcalendar-3.8.2/moment.min.js"></script>
        <script src="~/Content/js/fullcalendar-3.8.2/fullcalendar_Price.min.js"></script>
<script>
    var keyValue = $.request("keyValue");
    var F_MarketPrice = $.request("F_MarketPrice");
    var datalist = [];
    var datajson = {
        title: '',
        start: '',
        end: ''
    }
    $(function () {
        if (!!keyValue) {
            $.ajax({
                url: "/SiteManage/PriceSchedule/GetPriceScheduleJson",
                data: { F_SpaceId: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    var Lists = data;
                    //console.log(JSON.stringify(data));
                    var now = new Date();
                    for (var i = 0; i < 90; i++) {
                        var date = now.setDate(now.getDate() + 1);
                        var isvalue = false;
                        for (var j = 0; j < Lists.length; j++) {
                            //console.log("i:" + i + "  j:" + j);
                            //console.log("L:" + new Date(date).Format("yyyy-MM-dd") + "   R:" + new Date(Lists[j].F_ScheduleDate).Format("yyyy-MM-dd"));
                            if (new Date(date).Format("yyyy-MM-dd") == new Date(Lists[j].F_ScheduleDate).Format("yyyy-MM-dd")) {
                                isvalue = true;
                                var datajson = {
                                    title: "¥ " + Lists[j].F_MarketPrice,
                                    start: Lists[j].F_ScheduleDate,
                                    end: Lists[j].F_ScheduleDate,
                                    className:['red']
                                };
                                datalist.push(datajson);
                                RemoveValByIndex(Lists, j);
                                break; 
                            }
                        }
                        if (!isvalue) {
                            var datajson = {
                                title: "¥ " + F_MarketPrice,
                                start: new Date(date).Format("yyyy-MM-dd"),
                                end: new Date(date).Format("yyyy-MM-dd")
                            };
                            datalist.push(datajson);
                        }
                    }
                    //console.log(JSON.stringify(datalist));
                }
            });
        }
    });
    function RemoveValByIndex(arr, index) {
        arr.splice(index, 1);
    }
    $(document).ready(function () {
        var activityDate = "";
        var now = new Date().Format("yyyy-MM-dd");
        $('#calendar').fullCalendar({
            defaultDate: now,
            editable: true,
            selectable: true,
            eventLimit: true, // allow "more" link when too many events
            events: datalist
        });

    });

    Date.prototype.Format = function (fmt) { //author: meizz 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

</script>
<style>

    body {
        margin: 40px 10px;
        padding: 0;
        font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
        font-size: 14px;
    }

    .fc button, .fc-button-group, .fc-time-grid .fc-event .fc-time span {
        display: block;
    }

    ul {
        margin-left: -38px;
    }

    li {
        list-style-type: none;
        line-height: 15px;
        height: 30px;
    }

    #calendar {
        max-width: 700px;
        margin: 0 auto;
    }

    .color li span {
        border: 1px solid #e5e0e0;
        width: 20px;
        height: 10px;
        float: left;
        margin-right: 20px;
    }

    .white {
        background-color: white !important;
    }

    .red {
        background-color: #f19696 !important;
    }

    .yellow {
        background-color: #b2bf3a !important;
    }

    .removeli {
        font-size: 20px;
        font-weight: bold;
        margin-right: 16px;
        text-decoration: none;
    }
    .fc-event {
        border:0px;
    }
    tr:first-child > td > .fc-day-grid-event {
        margin-top: 13px;
    }
    .fc-unthemed .fc-content {
        text-align: center
    }
</style>

<div id='calendar' style="float:left;"></div>

